Fix: Match Solidity behavior for memory array deletion (issue #1785)#1795
Fix: Match Solidity behavior for memory array deletion (issue #1785)#1795guptapratykshh wants to merge 12 commits intohyperledger-solang:mainfrom
Conversation
…dger-solang#1785) Signed-off-by: Pratyksh <pratykshgupta9999@gmail.com>
f2d4df4 to
4de1994
Compare
seanyoung
left a comment
There was a problem hiding this comment.
Thank you for your contribution. The main problem is that output from sema should be the same as the source tree, i.e. you can't replace a delete statement with something else. Many components, e.g. solang language server, depend on the AST being accurate.
src/sema/statements.rs
Outdated
| // Issue #1785 - match Solc behavior for delete array[index] | ||
| ns.diagnostics.push(Diagnostic::warning( | ||
| *loc, | ||
| "argument to 'delete' should be storage reference".to_string(), |
There was a problem hiding this comment.
Here are you still generating a warning. Should be removed for array elements.
There was a problem hiding this comment.
No warnings are generated for memory array delete operations
src/sema/statements.rs
Outdated
| right: Box::new(default_expr), | ||
| }; | ||
|
|
||
| res.push(Statement::Expression(*loc, true, assign)); |
There was a problem hiding this comment.
The problem here is that the AST should be an accurate representation of the source code, not of the code it will generate - that happens in codegen.
So in sema, add:
res.push(Statement::Delete(...);Then in codegen, for array elements, set a default value, here:
https://github.com/hyperledger-solang/solang/blob/main/src/codegen/statements/mod.rs#L217
There was a problem hiding this comment.
handled array elements in codegen
src/sema/statements.rs
Outdated
| } | ||
|
|
||
| /// Helper function to get the default value expression for a type | ||
| fn get_default_value( |
There was a problem hiding this comment.
We already have a function for default values in codegen. Let me know if you need some help locating it
There was a problem hiding this comment.
Removed the redundant function
Signed-off-by: Pratyksh Gupta <pratykshgupta9999@gmail.com>
|
Please look into this @seanyoung |
…ferences as write operations
…for mutability analysis and warnings
…for mutability analysis and warnings
…te operations for mutability analysis
… for memory arrays and improve mutability analysis
Signed-off-by: Pratyksh Gupta <pratykshgupta9999@gmail.com>
Description
This PR fixes behavior of
deleteoperator when used with memory arrays to match Solidity's behavior. Previously, the delete operator was not correctly handling memory array elements, which could lead to unexpected behavior.Related Issue
Closes #1785